<?php

class LoginAction extends Action {

    public function index() {
        $this->display('login');
    }

    public function checkLogin() {
        # code...

        $username = I('post.username', '');
        $password = I('post.password', '');

        $res = D('Users')->checkLogin($username, $password);

        switch ($res) {
            case -1:
                $this->ajaxReturn(array('status' => -1, 'info' => '用户不存在', 'data' => null, 'jumpUrl' => null));
                break;
            case 0:
                $this->ajaxReturn(array('status' => 0, 'info' => '密码错误', 'data' => null, 'jumpUrl' => null));
                break;
            case 1:
                $this->ajaxReturn(array('status' => 1, 'info' => '登陆成功', 'data' => null, 'jumpUrl' => U('Main/index')));
                break;
        }
    }

    public function logout() {

        session_unset();
        session_destroy();
        $this->redirect('Admin/Login/index');
    }

}

?>